import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../assets/styles.dart';
import '../../../../components/image_view.dart';
import '../../../../model/advertisements/ad_resp_model.dart';
import '../../../../utils/ad_jump.dart';
import '../../../../utils/color.dart';
import '../../../../utils/enum.dart';
import '../../../../utils/extension.dart';
import '../../../../utils/initAdvertisementInfo.dart';

class ShortVPTopArea extends StatelessWidget {
  const ShortVPTopArea({super.key});

  Widget _buildAds(List<AdvertisementInfos> ads) {
    if (ads.isEmpty) return const SizedBox.shrink();
    final adChildren = ads.slices(4).map((e) {
      return Row(
        mainAxisSize: MainAxisSize.min,
        children: e
            .map((ad) => ImageView(
                  src: ad.adImage ?? '',
                  width: 66.w,
                  height: 66.w,
                  borderRadius: Styles.borderRadius.all(8.w),
                ).onTap(
                  () => kAdInfoJump(ad),
                ))
            .toList()
            .joinWidth(10.w),
      );
    }).toList();

    return ConstrainedBox(
      constraints: BoxConstraints(maxHeight: 0.65.sh),
      child: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: adChildren.joinHeight(10.w),
        ),
      ),
    );
  }

  Widget _buildTips() {
    return Container(
      width: 170.w,
      padding: EdgeInsets.symmetric(horizontal: 30.w, vertical: 2.w),
      decoration: BoxDecoration(
        color: COLOR.black.withValues(alpha: 0.5),
        borderRadius: Styles.borderRadius.all(13.5.w),
      ),
      alignment: Alignment.center,
      child: Text(
        'VIP用户去除广告',
        style: TextStyle(
          color: COLOR.color_FAA100,
          fontSize: 14.w,
          fontWeight: FontWeight.w500,
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final ads = initSequenceAdvertisementInfo(AdPlaceNameEnum.SV_PLAY_UN_VIP);
    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        if (ads.isNotEmpty) ...[
          _buildAds(ads),
          14.verticalSpaceFromWidth,
          _buildTips()
        ],
      ],
    );
  }
}
